#include "head.h"
void Change_grade (FlightSystem * Flight_list,U_node* ptr,int flag)
{
    if (flag == 1)
    {
        U_data data =ptr->data;
        ptr->data.grade = 2;
        S_List_insert(Flight_list->REGULAR_USER, ptr->data, 1);
        S_List_File_print(Flight_list->REGULAR_USER, REGULAR_FILE);
        dete_change (data,Flight_list);
    }
    if (flag == 2)
    {
        U_data data =ptr->data;
        ptr->data.grade = 3;
        S_List_insert(Flight_list->SILVER_USER, ptr->data, 1);
        S_List_File_print(Flight_list->SILVER_USER, SILVER_FILE);
        dete_change (data,Flight_list);
    }
    if (flag == 3)
    {
        U_data data =ptr->data;
        ptr->data.grade = 4;
        S_List_insert(Flight_list->GOLD_USER, ptr->data, 1);
        S_List_File_print(Flight_list->GOLD_USER, GOLD_FILE);
        dete_change (data,Flight_list);
    }
    if (flag == 4)
    {
        U_data data =ptr->data;
        ptr->data.grade = 5;
        S_List_insert(Flight_list->PLATINUM_USER, ptr->data, 1);
        S_List_File_print(Flight_list->PLATINUM_USER, PLATINUM_FILE);
        dete_change (data,Flight_list);
    }
    if (flag == 5)
    {
        U_data data =ptr->data;
        ptr->data.grade = 1;
        S_List_insert(Flight_list->ADMIN_USER, ptr->data, 1);
        S_List_File_print(Flight_list->ADMIN_USER, ADMIN_FILE);
        dete_change (data,Flight_list);
    }
    return ;
}

void dete_change (U_data data,FlightSystem * Flight_list)
{
    if (data.grade == 1)
        {
            int pos = find_user_by_name(Flight_list->ADMIN_USER, data.name); 
            S_List_delete(Flight_list->ADMIN_USER , pos);
            S_List_File_print(Flight_list->ADMIN_USER, ADMIN_FILE);
        }
        if (data.grade == 2)
        {
            int pos = find_user_by_name(Flight_list->REGULAR_USER, data.name); 
            S_List_delete(Flight_list->REGULAR_USER , pos);
            S_List_File_print(Flight_list->REGULAR_USER, REGULAR_FILE);
        }
        if (data.grade == 3)
        {
            int pos = find_user_by_name(Flight_list->SILVER_USER, data.name); 
            S_List_delete(Flight_list->SILVER_USER , pos);
            S_List_File_print(Flight_list->SILVER_USER, SILVER_FILE);
        }
        if (data.grade == 4)
        {
            int pos = find_user_by_name(Flight_list->GOLD_USER, data.name); 
            S_List_delete(Flight_list->GOLD_USER , pos);
            S_List_File_print(Flight_list->GOLD_USER, GOLD_FILE);
        }
        if (data.grade == 5)
        {
            int pos = find_user_by_name(Flight_list->PLATINUM_USER, data.name); 
            S_List_delete(Flight_list->PLATINUM_USER , pos);
            S_List_File_print(Flight_list->PLATINUM_USER, PLATINUM_FILE);
        }
        return ;
}

void add_super_user(U_list* list)
{
    U_data log_data;
    while (1)
        {
            printf("请输入新管理员的账号:\n");
            scanf("%s" , log_data.name);
            int K = S_List_find_name_n(list, log_data.name);
            if (K == 1)
            {
                printf("当前用户名已被注册\n");
            }
            else break;
        }
        printf("请输入的密码:\n");
        scanf("%s" , log_data.passwd);
        log_data.numTickets=0;
        log_data.value=1000;
        log_data.grade = 1;
        S_List_insert(list , log_data , 1);
        S_List_File_print( list , ADMIN_FILE );
        printf("恭喜您添加管理员用户成功,以下是管理员的用户信息:\n");
        S_List_print(list);
        sleep(2); 
        return ;
}

void delete_super_user(U_list* list)
{
    printf("以下是管理员用户信息\n");
    S_List_print(list);
    printf("请输入您要删除的管理员的账号:\n");
    char name[20];
    scanf("%s" , name);
    int pos = find_user_by_name(list , name);
    S_List_delete(list, pos);
    S_List_File_print( list , ADMIN_FILE );
    return ;
}